﻿using BLL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Web
{
    public partial class UserInfoAdjust : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserID"] != null)
                {
                    List<UserinforModel> list = UserinforManger.selectByUserID(int.Parse(Session["UserID"].ToString()));
                    Label1.Text = list[0].UserID.ToString();
                    TextBox1.Text = list[0].UName.ToString();
                    TextBox2.Text = list[0].UserAge.ToString();
                    TextBox3.Text = list[0].UsersSex.ToString();
                    TextBox4.Text = list[0].UserPhone.ToString();
                    TextBox5.Text = list[0].Address.ToString();


                }
                else
                {
                    Response.Write("<script>alert('操作错误')</script>");
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)//修改
        {
            if (Session["UserID"] != null)
            {
                if (TextBox1.Text.Equals("")||TextBox2.Text.Equals("") || TextBox3.Text.Equals("") || TextBox4.Text.Equals("") || TextBox5.Text.Equals(""))
                {
                    Label2.Text = "个人信息不能有空！";
                }
                else
                {
                    if (UserinforManger.updateByUserID(TextBox1.Text, int.Parse(TextBox2.Text.ToString()), TextBox3.Text, TextBox4.Text, TextBox5.Text, int.Parse(Session["UserID"].ToString())))
                    {
                        Response.Redirect("UpdateSuccessful.aspx");
                    }
                    else
                    {
                        Response.Write("<script>alert('操作错误！')</script>");
                    }
                }
            }
            else
            {
                Response.Write("<script>alert('操作错误')</script>");
            }
        }     
    }
}